package com.start.workflow.core.mappers;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.start.workflow.entity.StartActReModelExt;
import com.start.workflow.model.StartProcessModel;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface StartActReModelExtMapper extends BaseMapper<StartActReModelExt> {
    String listModelSql = "SELECT a.* FROM (" +
            "SELECT  " +
            "  sarm.*,  " +
            "  arm.VERSION_ act_model_version,  " +
            "  arm.NAME_ act_model_name,  " +
            "  arm.KEY_ act_model_key,  " +
            "  arm.CREATE_TIME_ create_time,  " +
            "  arm.LAST_UPDATE_TIME_ last_update_time,  " +
            "  arm.CATEGORY_ act_model_category  " +
            "FROM  " +
            "  act_re_model arm  " +
            "  LEFT JOIN start_act_re_model_ext sarm ON sarm.id = arm.ID_ ) a ";

    @Select("select a.* from ("+listModelSql+") a ${ew.customSqlSegment} ")
    Page<StartProcessModel> pageModel(@Param("page") Page<StartProcessModel> page, @Param("ew") Wrapper<StartProcessModel> wrapper);

    @Select(listModelSql + " where  id=#{modelId}")
    StartProcessModel getModelInfo(@Param("modelId") String modelId);


    @Select(listModelSql + " ${ew.customSqlSegment}")
    List<StartProcessModel> listModel(@Param("ew") Wrapper<StartProcessModel> wrapper);

    @Update("update start_act_re_model_ext set deploy_state=1,deploy_version=#{version} where id=#{modeId}")
    void updateModelDeploy(@Param("modeId") String modeId, @Param("version") Integer version);
}
